package com.jimmy.springcloud.controller;

import com.jimmy.springcloud.entities.Dept;
import com.jimmy.springcloud.service.DeptClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @version 1.0
 * @ ClassName DeptController_Consumer
 * <p> 直接注入API接口而不在是使用resttemplate来服务调用了
 * @ author JIMMY
 * @ Date 2020/11/17 0017 上午 11:18
 */
@RestController
public class DeptController_Consumer {


    @Autowired
    private DeptClientService deptClientService;

    //服务提供接口是 参考部门微服务器 IDepService的接口
//    public boolean add(Dept dept);
//
//    public Dept get(Long id);
//
//    public List<Dept> list();

    @RequestMapping(value = "/consumer/sys/dept/add")
    public boolean add(Dept dept)
    {
        return deptClientService.add(dept);
    }

    @RequestMapping(value = "/consumer/sys/dept/get/{id}")   //此方法有做了客户端服务降级
    public Dept get(@PathVariable("id") Long id)
    {
        return deptClientService.get(id);
    }

    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/consumer/sys/dept/list")
    public List<Dept> list()
    {
        return deptClientService.list();
    }

    @RequestMapping(value = "/consumer/sys/dept/get2/{id}")
    public Dept get2(@PathVariable("id") Long id)
    {
//        return deptClientService.get2(id);
        return deptClientService.getDepById(id);
    }
    @RequestMapping(value = "/consumer/sys/dept/get3/{id}")
    public Dept get3(@PathVariable("id") Long id)
    {
//        return deptClientService.get2(id);
        return deptClientService.get3(id);
    }

}
